﻿using System.Collections.Generic;
using System.Text;
using Yd.Domain.IDAL;
using System.Collections.Specialized;
using System.Web;
using Yd.Model;
using Yd.CommCls;
using System;

namespace Yd.BLL
{
    public class CommBll
    {
        private static readonly ICommDAL commdal = Yd.DALFactory.DataAccess.CreateLogDAL();

        /// <summary>
        /// 用户查询
        /// </summary>
        /// <param name="_pagesize"></param>
        /// <param name="_pageindex"></param>
        /// <param name="_total"></param>
        /// <param name="_querystring"></param>
        /// <returns></returns>
        public IList<object> Query_Admin(int _pagesize, int _pageindex, out int _total, out string _querystring)
        {
            yd_admin fadmin = new yd_admin();
            fadmin.admin = "";
            if (HttpContext.Current.Request.QueryString["UserName"] != null)
            {
                fadmin.admin = HttpContext.Current.Request.QueryString["UserName"].Trim();
            }
            StringBuilder sb = new StringBuilder();
            NameValueCollection QueryNV = HttpContext.Current.Request.QueryString;
            for (int i = 0; i < QueryNV.Count; i++)
            {
                if (QueryNV.GetKey(i).ToLower() != "page")
                {
                    sb.AppendFormat("&" + QueryNV.GetKey(i) + "={0}", QueryNV.Get(i));
                }
            }
            _querystring = sb.ToString().Trim();
            return commdal.Query_Admin(fadmin, _pagesize, _pageindex, out _total);
        }
        public IList<object> Query_Shop(int _pagesize, int _pageindex, out int _total, out string _querystring)
        {
            yd_shop fadmin = new yd_shop();
            fadmin.shopName = "";
            fadmin.remensele = "";
            if (HttpContext.Current.Request.QueryString["ShopName"] != null)
            {
                fadmin.shopName = HttpContext.Current.Request.QueryString["ShopName"].Trim();
            }
            if (HttpContext.Current.Request.QueryString["remensele"] != null)
            {
                fadmin.remensele = HttpContext.Current.Request.QueryString["remensele"].Trim();
            }
            StringBuilder sb = new StringBuilder();
            NameValueCollection QueryNV = HttpContext.Current.Request.QueryString;
            for (int i = 0; i < QueryNV.Count; i++)
            {
                if (QueryNV.GetKey(i).ToLower() != "page")
                {
                    sb.AppendFormat("&" + QueryNV.GetKey(i) + "={0}", QueryNV.Get(i));
                }
            }
            _querystring = sb.ToString().Trim();
            return commdal.Query_Shop(fadmin, _pagesize, _pageindex, out _total);
        }
        public IList<object> Query_Kazuo(int _pagesize, int _pageindex, out int _total, out string _querystring)
        {
            yd_kazuo fadmin = new yd_kazuo();
            fadmin.kzName = "";
            fadmin.shopid = HttpContext.Current.Request.QueryString["sid"].StrToInt();
            if (HttpContext.Current.Request.QueryString["kazuoName"] != null)
            {
                fadmin.kzName = HttpContext.Current.Request.QueryString["kazuoName"].Trim();
            }
            StringBuilder sb = new StringBuilder();
            //NameValueCollection QueryNV = HttpContext.Current.Request.QueryString;
            //for (int i = 0; i < QueryNV.Count; i++)
            //{
            //    if (QueryNV.GetKey(i).ToLower() != "page")
            //    {
            //        sb.AppendFormat("&" + QueryNV.GetKey(i) + "={0}", QueryNV.Get(i));
            //    }
            //}
            _querystring = sb.ToString().Trim();
            return commdal.Query_Kazuo(fadmin, _pagesize, _pageindex, out _total);
        }
        public IList<object> Querytz_user(int _pagesize, int _pageindex, out int _total, out string _querystring)
        {
            yd_users fnews = new yd_users();
            fnews.userName = "";
            if (HttpContext.Current.Request.QueryString["userName"] != null)
            {
                fnews.userName = HttpContext.Current.Request.QueryString["userName"].Trim();
            }
            StringBuilder sb = new StringBuilder();
            NameValueCollection QueryNV = HttpContext.Current.Request.QueryString;
            for (int i = 0; i < QueryNV.Count; i++)
            {
                if (QueryNV.GetKey(i).ToLower() != "page")
                {
                    sb.AppendFormat("&" + QueryNV.GetKey(i) + "={0}", QueryNV.Get(i));
                }
            }
            _querystring = sb.ToString().Trim();
            return commdal.Querytz_user(fnews, _pagesize, _pageindex, out _total);
        }

        public IList<object> QueryView_yd_order(int _pagesize, int _pageindex, out int _total, out string _querystring)
        {
            yd_order fnews = new yd_order();
            fnews.userName = "";
            fnews.shopName = "";
            fnews.kzName = "";
            fnews.orderStatus = -1;
            fnews.date1 = "";
            fnews.date2 = "";
            fnews.orderno = "";
            if (HttpContext.Current.Request["orderStatus"] != null)
            {
                fnews.orderStatus = HttpContext.Current.Request["orderStatus"].Trim().StrToInt();
            }
            if (HttpContext.Current.Request.QueryString["username"] != null)
            {
                fnews.userName = HttpContext.Current.Request.QueryString["username"].Trim();
            }
            if (HttpContext.Current.Request.QueryString["shopname"] != null)
            {
                fnews.shopName = HttpContext.Current.Request.QueryString["shopname"].Trim();
            }
            if (HttpContext.Current.Request.QueryString["kzName"] != null)
            {
                fnews.kzName = HttpContext.Current.Request.QueryString["kzName"].Trim();
            }
            if (HttpContext.Current.Request.QueryString["date1"] != null)
            {
                fnews.date1 = HttpContext.Current.Request.QueryString["date1"].Trim();
            }
            if (HttpContext.Current.Request.QueryString["date2"] != null)
            {
                fnews.date2 = HttpContext.Current.Request.QueryString["date2"].Trim();
            }
            if (HttpContext.Current.Request.QueryString["orderno"] != null)
            {
                fnews.orderno = HttpContext.Current.Request.QueryString["orderno"].Trim();
            }
            StringBuilder sb = new StringBuilder();
            NameValueCollection QueryNV = HttpContext.Current.Request.QueryString;
            for (int i = 0; i < QueryNV.Count; i++)
            {
                if (QueryNV.GetKey(i).ToLower() != "page")
                {
                    sb.AppendFormat("&" + QueryNV.GetKey(i) + "={0}", QueryNV.Get(i));
                }
            }
            _querystring = sb.ToString().Trim();
            return commdal.QueryView_yd_order(fnews, _pagesize, _pageindex, out _total);
        }

        public IList<object> Querytz_action(int _pagesize, int _pageindex, out int _total, out string _querystring)
        {
            yd_action fnews = new yd_action();
            fnews.actionName = "";
            fnews.actionType = -1;
            if (HttpContext.Current.Request.QueryString["actionName"] != null)
            {
                fnews.actionName = HttpContext.Current.Request.QueryString["actionName"].Trim();
            }
            if (HttpContext.Current.Request["actionStatus"] != null)
            {
                fnews.actionType = HttpContext.Current.Request["actionStatus"].Trim().StrToInt();
            }
            StringBuilder sb = new StringBuilder();
            NameValueCollection QueryNV = HttpContext.Current.Request.QueryString;
            for (int i = 0; i < QueryNV.Count; i++)
            {
                if (QueryNV.GetKey(i).ToLower() != "page")
                {
                    sb.AppendFormat("&" + QueryNV.GetKey(i) + "={0}", QueryNV.Get(i));
                }
            }
            _querystring = sb.ToString().Trim();
            return commdal.Query_Action(fnews, _pagesize, _pageindex, out _total);
        }
        public IList<object> Querytz_feedback(int _pagesize, int _pageindex, out int _total, out string _querystring)
        {
            yd_feedback fnews = new yd_feedback();
            fnews.userName = "";
            if (HttpContext.Current.Request.QueryString["userName"] != null)
            {
                fnews.userName = HttpContext.Current.Request.QueryString["userName"].Trim();
            }
           
            StringBuilder sb = new StringBuilder();
            NameValueCollection QueryNV = HttpContext.Current.Request.QueryString;
            for (int i = 0; i < QueryNV.Count; i++)
            {
                if (QueryNV.GetKey(i).ToLower() != "page")
                {
                    sb.AppendFormat("&" + QueryNV.GetKey(i) + "={0}", QueryNV.Get(i));
                }
            }
            _querystring = sb.ToString().Trim();
            return commdal.Query_Feedback(fnews, _pagesize, _pageindex, out _total);
        }
    }
}
